
let charaters = {
    keli : {
        name: "lv90可莉", 
        base: 311,
        criticalRate: 5,
        dmgRate:28.8,
        criticalStrike: 50
    }
}

let weapons = {
    sf: {
        name:"lv90四风",
        base: 608,
        criticalRate:33.1,
        dmgRate: 16*4
    },
    s: {
        name:"lv90锁",
        base: 608,
        attRate: 49.6 + 80
    },
    tk: {
        name:"lv90天空",   // 3.2 攻击力伤害
        base: 674,
        attRate:33.1,
        dmgRate: 24
    }
}
let normal_clips = calc_clips_normal();
let normal_clips2 = calc_clips_normal(2);
let charactersDmg = []
// 可利 四风
// charactersDmg.push(getDMG([charaters.keli,weapons.sf,{fixedAtt:311,criticalStrike:62.2,dmgRate:46.6,attRate:46.6},normal_clips2], (data,second) => {
//     // 魔女套 15火伤  每放次e + 7.5    0.15精通增伤
//     data.dmgRate += 15;
//     data.dmgRate += 20;
//     let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
//     let rea = { 精通:data.精通, 系数:1.5, 精通增伤:0.15 }
//     data.dmgRate += 7.5;
//     let e1 = getDmgDps(data, 1.71) * q(10) * df(90,90,23); 
//     let e1b = getDmgDps(data, 0.59) * q(10) * df(90,90,23); 
//     let e1Rea = getDmgDps(data, 1.71,rea) * q(10) * df(90,90,23); 
//     let e1bRea = getDmgDps(data, 0.59,rea) * q(10) * df(90,90,23); 
//     data.dmgRate += 7.5;
//     let e2 = getDmgDps(data, 1.71) * q(10) * df(90,90,23); 
//     let e2b = getDmgDps(data, 0.59) * q(10) * df(90,90,23); 
//     let e2Rea = getDmgDps(data, 1.71,rea) * q(10) * df(90,90,23); 
//     let e2bRea = getDmgDps(data, 0.59,rea) * q(10) * df(90,90,23); 

//     // q
//     let qd = getDmgDps(data, 0.768) * q(10) * df(90,90,23); 
//     let qdRea = getDmgDps(data, 0.768,rea) * q(10) * df(90,90,23); 
//     let qBoom = getDmgDps(data, 5.55,) * q(10) * df(90,90,23); 
//     let qBoomRea = getDmgDps(data, 5.55,rea) * q(10) * df(90,90,23); 

//     // a
//     let a1 = getDmgDps(data, 1.3) * q(10) * df(90,90,23);
//     let a1Rea = getDmgDps(data, 1.3, rea) * q(10) * df(90,90,23);
//     let aF = getDmgDps(data, 2.83) * q(10) * df(90,90,23);
//     let aFRea = getDmgDps(data, 2.83,rea) * q(10) * df(90,90,23);
//     data.dmgRate += 50;
//     let aFH = getDmgDps(data, 2.83) * q(10) * df(90,90,23);
//     let aFHRea = getDmgDps(data, 2.83,rea) * q(10) * df(90,90,23);

//     let ret = e1Rea + e1 + e2*2 + e1b*2 + e2b*2 + qd*15 + a1 * 8 + a1Rea*2 + aF*2 + aFRea + aFH*2 + aFHRea  + qBoomRea
//     return {point:ret, data, second, attack , msg:"四风反应",a1Rea,aFRea,aF}
// }))

// 可利 四风
charactersDmg.push(getDMG([charaters.keli,weapons.sf,{fixedAtt:311,criticalStrike:62.2,dmgRate:46.6,attRate:46.6},normal_clips2], (data,second) => {
    // 魔女套 15火伤  每放次e + 7.5    0.15精通增伤
    data.dmgRate += 15;
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:1.5, 精通增伤:0.15 }
    data.dmgRate += 7.5;
    let e1 = getDmgDps(data, 1.71) * q(10) * df(90,90); 
    let e1b = getDmgDps(data, 0.59) * q(10) * df(90,90); 
    let e1Rea = getDmgDps(data, 1.71,rea) * q(10) * df(90,90); 
    let e1bRea = getDmgDps(data, 0.59,rea) * q(10) * df(90,90); 
    data.dmgRate += 7.5;
    let e2 = getDmgDps(data, 1.71) * q(10) * df(90,90); 
    let e2b = getDmgDps(data, 0.59) * q(10) * df(90,90); 
    let e2Rea = getDmgDps(data, 1.71,rea) * q(10) * df(90,90); 
    let e2bRea = getDmgDps(data, 0.59,rea) * q(10) * df(90,90); 

    // q
    let qd = getDmgDps(data, 0.768) * q(10) * df(90,90); 
    let qdRea = getDmgDps(data, 0.768,rea) * q(10) * df(90,90); 
    let qBoom = getDmgDps(data, 5.55,) * q(10) * df(90,90); 
    let qBoomRea = getDmgDps(data, 5.55,rea) * q(10) * df(90,90); 

    // a
    let a1 = getDmgDps(data, 1.3) * q(10) * df(90,90);
    let a1Rea = getDmgDps(data, 1.3, rea) * q(10) * df(90,90);
    let aF = getDmgDps(data, 2.83) * q(10) * df(90,90);
    let aFRea = getDmgDps(data, 2.83,rea) * q(10) * df(90,90);
    data.dmgRate += 50;
    let aFH = getDmgDps(data, 2.83) * q(10) * df(90,90);
    let aFHRea = getDmgDps(data, 2.83,rea) * q(10) * df(90,90);

    let ret = e1Rea*2 + e2*2 + e1b*2 + e2b*2 + qd*15 + a1 * 6 + a1Rea*2 + aF*2 + aFRea + aFH + aFHRea + qBoomRea
    return {point:ret, data, second, attack , msg:"四风",}
}))

charactersDmg.push(getDMG([charaters.keli,weapons.tk,{fixedAtt:311,criticalStrike:62.2,dmgRate:46.6,attRate:46.6},normal_clips2], (data,second) => {
    // 魔女套 15火伤  每放次e + 7.5    0.15精通增伤
    data.dmgRate += 15;
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:1.5, 精通增伤:0.15 }
    data.dmgRate += 7.5;
    let e1 = getDmgDps(data, 1.71) * q(10) * df(90,90); 
    let e1b = getDmgDps(data, 0.59) * q(10) * df(90,90); 
    let e1Rea = getDmgDps(data, 1.71,rea) * q(10) * df(90,90); 
    let e1bRea = getDmgDps(data, 0.59,rea) * q(10) * df(90,90); 
    data.dmgRate += 7.5;
    let e2 = getDmgDps(data, 1.71) * q(10) * df(90,90); 
    let e2b = getDmgDps(data, 0.59) * q(10) * df(90,90); 
    let e2Rea = getDmgDps(data, 1.71,rea) * q(10) * df(90,90); 
    let e2bRea = getDmgDps(data, 0.59,rea) * q(10) * df(90,90); 

    // q
    let qd = getDmgDps(data, 0.768) * q(10) * df(90,90); 
    let qdRea = getDmgDps(data, 0.768,rea) * q(10) * df(90,90); 
    let qBoom = getDmgDps(data, 5.55,) * q(10) * df(90,90); 
    let qBoomRea = getDmgDps(data, 5.55,rea) * q(10) * df(90,90); 

    // a
    let a1 = getDmgDps(data, 1.3) * q(10) * df(90,90);
    let a1Rea = getDmgDps(data, 1.3, rea) * q(10) * df(90,90);
    let aF = getDmgDps(data, 2.83) * q(10) * df(90,90);
    let aFRea = getDmgDps(data, 2.83,rea) * q(10) * df(90,90);
    data.dmgRate += 50;
    let aFH = getDmgDps(data, 2.83) * q(10) * df(90,90);
    let aFHRea = getDmgDps(data, 2.83,rea) * q(10) * df(90,90);

    let wl = getDmgDps({...data, dmgRate: 0}, 3.2) * q(10) * df(90,90)

    let ret = e1Rea*2 + e2*2 + e1b*2 + e2b*2 + qd*15 + a1 * 6 + a1Rea*2 + aF*2 + aFRea + aFH + aFHRea + qBoomRea + wl * 7
    return {point:ret, data, second, attack , msg:"天空",wl}
}))

charactersDmg.push(getDMG([charaters.keli,weapons.s,{fixedAtt:311,criticalStrike:62.2,dmgRate:46.6,attRate:46.6},normal_clips2], (data,second) => {
    // 魔女套 15火伤  每放次e + 7.5    0.15精通增伤
    data.dmgRate += 15;
    let attack = data.base *(1 + data.attRate/100) + data.fixedAtt
    let rea = { 精通:data.精通, 系数:1.5, 精通增伤:0.15 }
    data.dmgRate += 7.5;
    let e1 = getDmgDps(data, 1.71) * q(10) * df(90,90); 
    let e1b = getDmgDps(data, 0.59) * q(10) * df(90,90); 
    let e1Rea = getDmgDps(data, 1.71,rea) * q(10) * df(90,90); 
    let e1bRea = getDmgDps(data, 0.59,rea) * q(10) * df(90,90); 
    data.dmgRate += 7.5;
    let e2 = getDmgDps(data, 1.71) * q(10) * df(90,90); 
    let e2b = getDmgDps(data, 0.59) * q(10) * df(90,90); 
    let e2Rea = getDmgDps(data, 1.71,rea) * q(10) * df(90,90); 
    let e2bRea = getDmgDps(data, 0.59,rea) * q(10) * df(90,90); 

    // q
    let qd = getDmgDps(data, 0.768) * q(10) * df(90,90); 
    let qdRea = getDmgDps(data, 0.768,rea) * q(10) * df(90,90); 
    let qBoom = getDmgDps(data, 5.55,) * q(10) * df(90,90); 
    let qBoomRea = getDmgDps(data, 5.55,rea) * q(10) * df(90,90); 

    // a
    let a1 = getDmgDps(data, 1.3) * q(10) * df(90,90);
    let a1Rea = getDmgDps(data, 1.3, rea) * q(10) * df(90,90);
    let aF = getDmgDps(data, 2.83) * q(10) * df(90,90);
    let aFRea = getDmgDps(data, 2.83,rea) * q(10) * df(90,90);
    data.dmgRate += 50;
    let aFH = getDmgDps(data, 2.83) * q(10) * df(90,90);
    let aFHRea = getDmgDps(data, 2.83,rea) * q(10) * df(90,90);

    let ret = e1Rea*2 + e2*2 + e1b*2 + e2b*2 + qd*15 + a1 * 6 + a1Rea*2 + aF*2 + aFRea + aFH + aFHRea + qBoomRea
    return {point:ret, data, second, attack , msg:"锁",}
}))

console.log(charactersDmg.sort((a,b)=>b.point-a.point));

function getDMG(dataarr, getRet){
    let chance = 25;
    let _ret = [];
    for (let index = 0; index <= chance; index++) {
        let criticalStrike = index; 
        for (let index2 = 0; index2 <= chance - index; index2++) {
            let criticalRate = index2;
            for (let index3 = 0; index3 <= chance-index-index2; index3++) {
                let attRate = index3;
                let defenceRate = chance - index - index2 - index3;
                _ret.push({
                    精通: 7.3 * defenceRate,
                    attRate:5.8 * attRate,
                    criticalRate:3.9 * criticalRate,
                    criticalStrike:7.8 * criticalStrike
                });
            }
        }
    }
    _ret = _ret.map(second => {
        let panel = getPanel([...dataarr, second]);
        return  getRet(panel, second)
    })
    _ret.sort((b,a)=> a.point-b.point)
    return _ret[0]
}

function getDmgDps(data, rate=1, rea){
    let criticalRate = data.criticalRate
    if(criticalRate > 100){criticalRate = 100}
    let baseat = data.base * (1 + data.attRate/100) + data.fixedAtt;
    let bdmg = baseat * (1 + data.criticalStrike/100);
    let bdps = (criticalRate * 10 * bdmg + (1000-criticalRate * 10)*baseat)/1000
    let adddmg = bdps * (1 + data.dmgRate/100)
    if(rea){
        let {精通, 系数, 精通增伤} = rea
        let tmp = 1 + 精通增伤 + jt(精通);
        return adddmg * rate * 系数 * tmp
    }
    return adddmg * rate
}

function getPanel(arr){
    let info = {name1:"",name2:""};
    arr.forEach((item, i)=>{
        if(item.name){
            info["name" + (i+1)] = item.name
        }
        for (const key in item) {
            if(key !== "name"){
                if(info[key]){
                    info[key] += item[key]
                } else {
                    info[key] = item[key]
                }
            }
        }
    })
    return info
}

function q (resistance) {
    if(resistance < 0) {
        return 1 - resistance/200
    } else if (resistance >=0 && resistance < 75){
        return 1 - resistance/100
    } else {
        return 1/(1+resistance/100*4)
    }
}

function df(youLv=0, eLv=0, td){
    return (100+youLv)/(100+youLv+(100+eLv)*(td? (100-td)/100 : 1))
}

// 固定攻击力 19  防御力23 生命值299 5.3% 
function calc_clips_normal (n) {
    let clips = [
        {
            fixedAtt:193,
            attRate: 5.8,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            fixedAtt:19,
            attRate: 5.8,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            fixedAtt:19,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            fixedAtt:19,
            attRate: 5.8,
            criticalRate: 3.9,
            criticalStrike:7.8
        },
        {
            fixedAtt:19,
            attRate: 5.8,
            criticalRate:n!=2? 0:3.9,
            criticalStrike:n!=2? 7.8:0
        }
    ]
    let data = {}
    clips.forEach(item => {
        for (const key in item) {
            data[key] = data[key]? (data[key]+item[key]) : item[key]
        }
    })
    return data
}

function jt(k){
    return Math.log(0.99316499 + 0.00209988607 * k + 0.0000001213236971*k*k)
}